package com.cn.lyl.lawyer.controller;

import com.cn.lyl.lawyer.model.entity.LawyerRoleModel;
import com.cn.lyl.lawyer.model.vo.LawyerRoleVo;
import com.cn.lyl.lawyer.service.LawyerService;
import com.cn.lyl.lawyer.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/back/lawyer")

public class LawyerController {
    @Autowired
    private LawyerService lawyerService;

    @PostMapping("/add")
    public Object add(LawyerRoleVo lawyerRoleVo){
        lawyerService.add(lawyerRoleVo);
        return CommonResult.success(null);
    }
    @PostMapping("/changeHomeState")
    public Object changeHomeState(Integer id){
        lawyerService.changeHomeState(id);
        return CommonResult.success(null);
    }
    @PostMapping("/delete")
    public Object delete(Integer id){
        lawyerService.delete(id);
        return CommonResult.success(null);
    }

    @PostMapping("/edit")
    public Object edit(LawyerRoleVo lawyerRoleVo){
        lawyerService.change(lawyerRoleVo);
        return CommonResult.success(null);
    }

    @GetMapping("/list")
    public Object findAll(LawyerRoleVo lawyerRoleVo){
        List<LawyerRoleVo> all = lawyerService.findAll(lawyerRoleVo);
       /* List<LawyerRoleVo> changeImgs = new ArrayList<>();
        for(LawyerRoleVo changeImg:all){
            changeImg.setHead("<img src='"+changeImg.getHead()+"'>");
            changeImgs.add(changeImg);
        }*/
        Map map = new HashMap();
        map.put("count",lawyerService.getCount(lawyerRoleVo));
        map.put("list",all);
        return CommonResult.success(map);
    }

    @GetMapping("/findInfo")
    public Object findById(Integer id){
        LawyerRoleVo byId = lawyerService.findById(id);
        return CommonResult.success(byId);
    }

    @GetMapping("/role")
    public Object findRole(){
        List<LawyerRoleModel> allRole = lawyerService.findAllRole();
        return CommonResult.success(allRole);
    }



}
